package cn.cxq.learning.recursion;

import org.junit.jupiter.api.Test;

import java.util.List;

public class Client {
    public static void main(String[] args) {

        testMaze();

        System.out.println("-----------------------------------");

        testEightQueue();
    }

    public static void testEightQueue() {
        System.out.println("8皇后问题：\n");

        EightQueue eightQueue = new EightQueue();
        List<int[]> plans = eightQueue.startAndGetPlans();

        System.out.println("所有可能的情况：");

        for (int[] plan : plans) {
            for (int i = 0; i < plan.length; i++) {
                System.out.print(plan[i] + " ");
            }
            System.out.println();
        }

        System.out.println("方案的个数：" + eightQueue.getPlanCount());
        System.out.println("检查次数：" + eightQueue.getCheckCount());
    }

    public static void testMaze() {
        System.out.println("迷宫问题：\n");

        int minStap = Integer.MAX_VALUE;

        List<int[][]> plans = Maze.generateGoPlan();

        int no = 1;
        for (int[][] plan : plans) {

            System.out.println("第" + no++ + "种走迷宫策略：");

            for (int i = 0; i < plan.length; i++) {

                System.out.print("[" + plan[i][0] + "," + plan[i][1] + "] ");

            }

            System.out.println();

            Maze maze = new Maze(plan);
            maze.go(1, 1);

            System.out.println("走过的路径：");
            maze.showMap();

            System.out.println("步数：" + maze.getStap());

            if (maze.getStap() < minStap) minStap = maze.getStap();

            System.out.println("---------------------------------");
        }

        System.out.println("最小步数：" + minStap);
    }

    @Test
    public void testKnightTour() {
        KnightTour knightTour = new KnightTour(8);

        long before = System.currentTimeMillis();

        knightTour.execute(new int[]{0, 0}, 0);

        long after = System.currentTimeMillis();

        System.out.println("用时：" + (after - before) / 1000.0 + "秒。");

        knightTour.printCheckerboard();
    }
}
